package com.jic.manager.controller;
import com.jic.common.base.vo.RestResult;
import com.jic.member.constant.consist.ResponseCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.BeanUtils;
import com.github.pagehelper.PageInfo;
import java.util.List;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import com.alibaba.fastjson.JSONObject;
import com.jic.manager.model.vo.request.SysLoginImageRequest;
import com.jic.manager.model.vo.response.SysLoginImageResponse;
import com.jic.manager.model.entity.SysLoginImage;
import com.jic.manager.service.SysLoginImageService;
/**
 * @Author: admin
 * @date: 2020-11-26 18:13:28
 */
 @RestController
 @Slf4j
 @RequestMapping("/sysLoginImage")
 @Api(tags = " [登录图片]控制类-PC")
public class SysLoginImageController {
	@Autowired
	private SysLoginImageService service;
	
	
     /**
      *新增记录
      * @param request 新增[登录图片]请求参数
      * @return SysLoginImageResponse 新增[登录图片]响应参数
      * author admin
      * @date 2020-3-11 20:54:04
      */
    @ApiOperation(value = "新增[登录图片]记录")
    @PostMapping("/save")
    @ResponseBody
    public RestResult<Long> save(@RequestBody SysLoginImageRequest request) throws Throwable {
     		SysLoginImage sysLoginImage = new SysLoginImage();
    		BeanUtils.copyProperties(request, sysLoginImage);
    	    long flag = service.save(sysLoginImage);
     return RestResult.success(flag);
    }
	
     /**
      * 新增或修改记录
      * @param request 新增或修改[登录图片]请求参数
      * @return SysLoginImageResponse 新增或修改[登录图片]响应参数
      * author admin
      * @date 2020-3-11 20:54:04
      */
     @ApiOperation(value = "保存或更新[登录图片]")
     @PostMapping("/saveOrUpdate")
      @ResponseBody
     public RestResult<Long> saveOrUpdate(@Validated @RequestBody SysLoginImageRequest request) throws Throwable {
      		SysLoginImage sysLoginImage = new SysLoginImage();
		     BeanUtils.copyProperties(request, sysLoginImage);
	         long flag =   service.saveOrUpdate(sysLoginImage);
      return RestResult.success(flag);
     }
	
     /**
      * 删除记录
      * @param request 删除[登录图片]请求参数
      * @return SysLoginImageResponse 删除[登录图片]响应参数
      * author admin
      * @date 2020-3-11 20:54:04
      */
     @ApiOperation(value = "删除[登录图片]记录")
     @PostMapping("/delete")
     @ResponseBody
     public RestResult<Long> delete(@RequestBody SysLoginImageRequest request) throws Throwable {
      		SysLoginImage sysLoginImage = new SysLoginImage();
	     	BeanUtils.copyProperties(request, sysLoginImage);
	         long flag = service.deleteByPrimaryKeyLogically(sysLoginImage);
      return RestResult.success(flag);
     }
	
     /**
      * 修改记录
      * @param request 修改[登录图片]请求参数
      * @return SysLoginImageResponse 修改[登录图片]响应参数
      * author admin
      * @date 2020-3-11 20:54:04
      */
     @ApiOperation(value = "修改[登录图片]记录")
     @PostMapping("/update")
     @ResponseBody
     public RestResult<Long> update(@RequestBody SysLoginImageRequest request) throws Throwable {
      		SysLoginImage sysLoginImage = new SysLoginImage();
	     	BeanUtils.copyProperties(request, sysLoginImage);
	         long flag = service.updateByPrimaryKeySelective(sysLoginImage);
      return RestResult.success(flag);
     }
	
     /**
      * 单表查询详情信息
      * @param request 查询[登录图片]详情请求参数
      * @return SysLoginImageResponse 查询[登录图片]详情响应参数
      * author admin
      * @date 2020-3-11 20:54:04
      */
      @PostMapping("/getByPrimaryKey")
      @ApiOperation(value = "查询[登录图片]详情")
      @ResponseBody
     public RestResult<SysLoginImageResponse> getByPrimaryKey(@Validated  @RequestBody SysLoginImageRequest request) {
     	log.info("查询详情请求参数入参，{}", JSONObject.toJSONString(request));
	     if (request!=null && request.getId()!=null) {
	      
	     	SysLoginImage sysLoginImage = new SysLoginImage();
	     	BeanUtils.copyProperties(request, sysLoginImage);
	     	SysLoginImage result = service.getByPrimaryKey(sysLoginImage);
		     log.info("查询详情请求参数出参，{}", JSONObject.toJSONString(result));
		     if (result == null) {
		     	return RestResult.error(ResponseCode.EXCEPTION, "记录不存在");
		     }
		     SysLoginImageResponse bo = new SysLoginImageResponse();
		     BeanUtils.copyProperties(result, bo);
	     	return RestResult.success(bo);
	     }
     	log.info("查询详情请求结束");
	     return RestResult.success(new SysLoginImageResponse());
     }
	
    /**
      * 分页查询
      *
      * @param request 分页查询请求参数
      * @return 分页列表
      * @throws Throwable 业务异常和系统异常
      */
     @PostMapping("/listPage")
     @ApiOperation(value = " 分页查询列表 ")
     @ResponseBody
     public RestResult<PageInfo<SysLoginImage>> listPage (@RequestBody SysLoginImageRequest request) throws Throwable {
      SysLoginImage param = new SysLoginImage();
      BeanUtils.copyProperties(request, param);
      param.setDeleteFlag(0);
     return RestResult.success(service.listPageBySelective(param, request.getPageNum(),request.getPageSize()));
     }
     
	
      /**
       *SYS_LOGIN_IMAGE 查询列表（不分页）
       * @param  request 前端请求参数
       */
      @PostMapping("/listAll")
      @ApiOperation(value = "不分页查询 [登录图片] ")
      @ResponseBody
      public RestResult<List<SysLoginImageResponse>>  listSysLoginImageAllRecord(@RequestBody SysLoginImageRequest request) throws Throwable {
      		SysLoginImage param = new SysLoginImage();
	     	BeanUtils.copyProperties(request, param);
	     	param.setDeleteFlag(0);
	     	List<SysLoginImage> list = service.listAllRecord(param);
			List<SysLoginImageResponse> responseList = list.stream().map(temp -> {
			SysLoginImageResponse bo = new SysLoginImageResponse();
			BeanUtils.copyProperties(temp, bo);
			return bo;
			}).filter(item -> item != null).collect(Collectors.toList());
		    return RestResult.success(responseList);
      }

     }

	
